<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchTable'>
      <f-search-form-item label='姓名' name='saleManName' />
    </f-search-form>
    <f-table ref='table' rowKey='saleManId' :scroll='{x:true}' :columns='columns' handler='saleManTaskTab1ListHandler' :multiple='false' :operator='operator' :params='queryParam' :api='api.tasktodo'>
      <span slot='salemanState' slot-scope='text, record, index'>
          <a-switch v-model='record.salemanState==1' checkedChildren='启用' unCheckedChildren='禁用' @change='(checked) => setSalemanState(checked,record)' />
        </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a v-if="record.assignee=='' && record.salemanState==-1" @click='claimTask(record)'>认领</a>
            <a @click='$refs.drawer.showDrawer(record)' v-if="record.assignee!='' && record.salemanState==-1">办理</a>
             <a-divider type='vertical' />
          </template>
         <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime=='' && record.salemanState==-1">
                <a href='javascript:;' @click='unClaimTask(record)'>取消认领</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='processImg(record)'>审批进度</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <saleman-drawer ref='drawer' @success='onLoad'></saleman-drawer>
  </div>
</template>
<script>
import salemanDrawer from "./components/saleman_drawer.vue"
import api from "../../js/api"
import { processMixins } from "@/core/mixins/processMixins"
import ProcessImage from "@/views/module/flowable/process/process_image"

export default {
  name: "Tab1",
  components: {
    ProcessImage,
    salemanDrawer
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "删除",
      icon: "delete",
      batch: true,
      handler: function(table) {
        table.remove()
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        fileName: "业务员明细",
        isFlp: 1,
        deptType: "ZY"
      },
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "唯一编号",
          align: "center",
          width: "80px",
          dataIndex: "saleManCode"
        },
        {
          title: "姓名",
          align: "center",
          width: "110px",
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          width: "120px",
          dataIndex: "saleManBusinessNo"
        },
        {
          title: "负责区域",
          align: "left",
          width: "100px",
          dataIndex: "areaName"
        },
        {
          title: "区域编码",
          align: "center",
          width: "100px",
          dataIndex: "orderNum"
        },

        {
          title: "部门",
          align: "left",
          width: "120px",
          dataIndex: "deptName"
        },
        {
          title: "职务",
          align: "center",
          width: "100px",
          dataIndex: "positionName"
        },

        {
          title: "招募人",
          align: "center",
          width: "100px",
          dataIndex: "parentName"
        }, {
          title: "身份证",
          align: "center",
          width: "120px",
          ellipsis: true,
          dataIndex: "cardNo"
        },
        {
          title: "联系电话",
          align: "center",
          width: "100px",
          dataIndex: "linkTel"
        },
        {
          title: "操作",
          align: "center",
          width: "150px",
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    //设置状态
    setSalemanState(check, record) {
      this.http.post(this, {
        url: this.api.saleMan.setSalemanState,
        data: {
          ids: record.saleManId,
          salemanState: Number(check)
        },
        success(me, data) {
          record.salemanState = data
        }
      })
    },
    syncToHy(record) {
      this.http.confirm(this, {
        content: "确认同步业务员到ERP吗?",
        data: {
          saleManId: record.saleManId
        },
        url: api.saleMan.syncToHy,
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    onLoad() {
      this.$refs.table.refresh()
    },
    searchTable(searchParams) {
      this.searchParams = searchParams
      this.$refs.table.refresh(true, searchParams)
    }
  }
}
</script>
